<template>
  <div class="table-container">
    <div class="table-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{path:'activityList'}">活动列表</el-breadcrumb-item>
        <el-breadcrumb-item>节目列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="table-search">
      <el-row>
        <el-input
          style="width: 200px;margin-right: 10px"
          placeholder="请输入关键字检索"
          v-model="keyword"
          clearable
          @clear="queryList"
        >
        </el-input>
        <el-button type="primary" @click="queryList">搜索</el-button>
      </el-row>
    </div>
    <div class="table-content">
      <div class="table-bar">

      </div>
      <el-table
        border
        empty-text="当前数据空空如也"
        ref="multipleTable"
        :data="partys"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column prop="id" label="ID" width="60"></el-table-column>
        <el-table-column prop="name" label="商家"></el-table-column>
        <el-table-column prop="mobile" label="电话" width="auto"></el-table-column>
        <el-table-column prop="type" label="作品类型" width="auto">
          <template slot-scope="scope">
            <p v-if="scope.row.type == 0">图片</p>
            <p v-else-if="scope.row.type == 1">视频</p>
          </template>
        </el-table-column>
        <el-table-column prop="opus" label="参赛作品" width="auto">
          <template slot-scope="scope">
            <div>
              <el-image
                v-if="scope.row.type == 0"
                style="width: 100px; height: 100px"
                :src="scope.row.opus"
                :preview-src-list="[scope.row.opus]">
              </el-image>
              <i ref="btn" v-if="scope.row.type == 1" style="font-size:35px" slot="reference" class="el-icon-video-play"
                 @click="playerVideo(scope.row.opus)"></i>
            </div>
          </template>

        </el-table-column>
        <el-table-column prop="address" label="店址" width="auto"></el-table-column>
        <el-table-column prop="support_num" label="点赞数" width="auto"></el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              style="margin-right: 5px"
              @click="handleDetails(scope.$index, scope.row)">详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="page-nav">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 20, 30, 50,100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
    <el-dialog title :visible.sync="dialogPlay" width="30%" @close="closeDialog">
      <video :src="videoUrl" controls autoplay class="video" ref="dialogVideo"
             width="100%"></video>
    </el-dialog>

    <el-drawer
      title="查看详情"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
    >
      <div>
        <el-form ref="form" :model="party" label-width="80px">
          <el-form-item label="联系人">
            <span>{{party.name}}</span>
          </el-form-item>
          <el-form-item label="联系电话">
            <span>{{party.mobile}}</span>
          </el-form-item>
          <el-form-item label="作品名称">
            <span>{{party.mobile}}</span>
          </el-form-item>
          <el-form-item label="作品文件">
            <div>
              <el-image
                v-if="party.type == 0"
                style="width: 100px; height: 100px"
                :src="party.opus"
                :preview-src-list="[party.opus]">
              </el-image>
              <i ref="btn" v-if="party.type == 1" style="font-size:35px" slot="reference" class="el-icon-video-play"
                 @click="playerVideo(party.opus)"></i>
            </div>
          </el-form-item>
          <el-form-item label="作品介绍">
            <span>{{party.content}}</span>
          </el-form-item>
          <el-form-item label="地址">
            <span>{{party.address}}</span>
          </el-form-item>
        </el-form>
      </div>
    </el-drawer>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        page: 1,
        pageSize: 10,
        total: 0,
        keyword: '',
        partys: [],
        dialogPlay: false,
        videoUrl: '',
        party: {},
        drawer: false,
        direction: 'rtl',

      }
    },
    mounted() {
      this.queryList();
    },
    methods: {
      handleDetails(index, row) {
        this.drawer = true;
        this.party =  {
          ...row
        }
      },

      handleClose(done) {
        done();
        this.party = {};
      },

      playerVideo(url) {
        this.dialogPlay = true;
        this.videoUrl = url;
      },

      closeDialog() {
        this.videoUrl = "";
      },

      handleSizeChange(val) {
        this.pageSize = val;
        this.page = 1;
        this.queryList()
      },
      handleCurrentChange(val) {
        this.page = val;
        this.queryList();
      },
      queryList() {
        let party_id = this.$route.query.id?this.$route.query.id:'';
        this.$http.get('/api/root/party/opusList', {
          page: this.page,
          pagesize: this.pageSize,
          keyword: this.keyword,
          party_id
        }).then(rest => {
          if (rest.code == 1) {
            this.partys = rest.data.data;
            this.total = rest.data.count;
          }
        })
      },
    }
  }
</script>
<style lang="less" scoped>
  @import 'index.less';
</style>
